package com.cheeven.cwliu.citation.steps;

import java.util.HashMap;
import org.w3c.dom.Document;

public class Step2 extends StepBase {

	public static void searchArticles(HashMap<String, String> control) {
		logInfo("2. Submit the Search Form");

		String journalName = control.get(getAppPrefix() + ".journal.name");
		String action = control.get("nextAction");
		String sid = control.get("sid");
		String saParams = control.get("saParams");

		logInfo(1, "Journal Name={0}", journalName);
		logInfo(1, "sid={0}", control.get("sid"));
		logInfo(1, "saParams={0}", control.get("saParams"));
		logInfo(1, "Search Form Action={0}", control.get("nextAction"));

		String searchPage = httpPost(action,
				new String[][]{
					{"fieldCount", "3"},
					{"action", "search"},
					{"product", "UA"},
					{"search_mode", "GeneralSearch"},
					{"SID", sid},
					{"max_field_count", "25"},
					{"max_field_notice", "Notice: You cannot add another field."},
					{"input_invalid_notice", "Search Error: Please enter a search term."},
					{"input_invalid_notice_limits", " <br/>Note: Fields displayed in scrolling boxes must be combined with at least one other search field."},
					{"sa_params", saParams},
					{"sa_img_alt", "Select terms from the index"},
					{"value(input1)", journalName},
					{"value(select1)", "SO"},
					{"value(hidInput1)", "SO"},
					{"value(hidShowIcon1)", "1"},
					{"value(bool_1_2)", "AND"},
					{"value(input2)", ""},
					{"value(select2)", "AU"},
					{"value(hidInput2)", "AU"},
					{"value(hidShowIcon2)", "1"},
					{"value(bool_2_3)", "AND"},
					{"value(input3)", ""},
					{"value(select3)", "SO"},
					{"value(hidInput3)", "SO"},
					{"value(hidShowIcon3)", "1"},
					{"x", "205"},
					{"y", "436"},
					{"limitStatus", "expanded"},
					{"expand_alt", "Expand these settings"},
					{"expand_title", "Expand these settings"},
					{"collapse_alt", "Collapse these settings"},
					{"collapse_title", "Collapse these settings"},
					{"ss_lemmatization", "On"},
					{"SinceLastVisit_UTC", ""},
					{"SinceLastVisit_DATE", ""},
					{"timespanStatus", "display: block"},
					{"timeSpanCollapsedListStatus", "display: none"},
					{"period", "Range Selection"},
					{"range", "ALL"},
					{"startYear", "1900"},
					{"endYear", "2013"},
					{"ss_query_language", ""},
					{"rsStatus", "display: none"},
					{"rs_rec_per_page", "10"},
					{"rs_sort_by", "PY.D;LD.D;SO.A;VL.D;PG.A;AU.A"},
					{"rs_refinePanel", "visibility: show"}});

		Document domdoc = toDOM(searchPage);

		control.put("sid", xpath("//input[@name='SID']/@value", domdoc));
		control.put("qid", xpath("//input[@name='qid']/@value", domdoc));

	}
}
